package com.cy.zs.hp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cy.zs.hp.mapper.SchedulingTableMapper;
import com.cy.zs.hp.model.SchedulingTable;
import com.cy.zs.hp.service.ISchedulingTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 该表为医师排班表及候诊人数状态表 服务实现类
 * </p>
 *
 * @author cgb2008
 * @since 2020-11-28
 */
@Service
public class SchedulingTableServiceImpl extends ServiceImpl<SchedulingTableMapper, SchedulingTable> implements ISchedulingTableService {
    @Autowired
    private SchedulingTableMapper schedulingTableMapper;

    //    挂号方法          医生id        预约时间

    public void setdoctor(Integer id, String worktime) {
        Integer people = schedulingTableMapper.find1(id, worktime);

        if (people >0) {
            people = people - 1;
            schedulingTableMapper.updatepeople(people, id, worktime);
            //people = schedulingTableMapper.find1(id, worktime);
            if(people==0){
                System.out.println("剩余人数："+people);
                schedulingTableMapper.deletepeople(people);
            }
        }
    }
    /**
     * 根据医生Id查询
     * @param id
     * @return
     */
    @Override
    public List<SchedulingTable> findByDoctorId(Integer id) {
        List<SchedulingTable> times = schedulingTableMapper.findByDoctorId(id);
        return times;
    }

    @Override
    public void deleteById(Integer id) {
        schedulingTableMapper.deleteById(id);
    }

    /**
     * 呈现数据
     */
    @Override
    public List<SchedulingTable> addgh() {
        List<SchedulingTable> find = schedulingTableMapper.findxx();
        return find;
    }

}
